package com.abp.controller;

import com.abp.entity.UserBookRating;
import com.abp.service.UserBookRatingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/user-book-ratings")
public class UserBookRatingController {

    @Autowired
    private UserBookRatingService userBookRatingService;

    @GetMapping
    public List<UserBookRating> getAllRatings() {
        return userBookRatingService.list();
    }

    @GetMapping("/{id}")
    public UserBookRating getRatingById(@PathVariable int id) {
        return userBookRatingService.getById(id);
    }

    @PostMapping
    public boolean addRating(@RequestBody UserBookRating userBookRating) {
        return userBookRatingService.save(userBookRating);
    }

    @PutMapping("/{id}")
    public boolean updateRating(@PathVariable int id, @RequestBody UserBookRating userBookRating) {
        userBookRating.setUserId(id);
        return userBookRatingService.updateById(userBookRating);
    }

    @DeleteMapping("/{id}")
    public boolean deleteRating(@PathVariable int id) {
        return userBookRatingService.removeById(id);
    }
}
